#ifndef BACKINSTANCE_H
#define BACKINSTANCE_H

#include <QObject>
#include <QVector>
#include <qtcpserver.h>
#include <qtcpsocket.h>

#include "_Interface/_global_datastruct.h"
#include "_Interface/_interface_backend.h"

#include "Package/oxfordlasersensordll_global.h"

class backinstance : public BackendInterface{
private:
    int            EKRLClient;
    ENUM_WorkModel WorkModel;
    ENUM_WorkType  WorkType;
    ST_ButtonStatus *pButtonStatus = nullptr;
    ST_RobotDAQData* pRobotDAQData = nullptr;
    ST_SeamFindingData* pSeamFindingData = nullptr;
    ST_Hand2EyesMatrix* pHand2EyesMatrix = nullptr;
    ST_LaserSensorData* pLaserSensorData = nullptr;
    ST_DataSaveParam mDataSaveParam;
    ST_Hand2EyesCalibrationData Hand2EyesCalibrationData[6];
    OxfordLaserSensorDLL* pOxfordLaserSensor = nullptr;
    QVector<ST_LaserSeamDataByPCS> vecLaserSeamDataByPCS;
public:
    backinstance();
    ~backinstance();
public:
    void onbtnClickedSensorConnect();
    void onbtnClickedRobotTCPConnect();
    void onbtnClickedRobotUDPConnect();
    void onbtnClickedTaskNull();
    void onbtnClickedCalibration();
    void onbtnClickedSeamFinding();
    void onbtnClickedSeamFindingStart2End();
    void onbtnClickedSeamTracking();
    void onbtnClickedCalPos1();
    void onbtnClickedCalPos2();
    void onbtnClickedCalPos3();
    void onbtnClickedCalPos4();
    void onbtnClickedCalPos5();
    void onbtnClickedCalPos6();
    void onbtnClickedCalibrationDo(double &X,double &Y,double &Z,double &A,double &B,double &C);
    void onbtnClickedCalibrationReset();
    void onbtnClickedPointRecord();
    void onbtnClickedWorkType();
    void onbtnClickedSeamPosCal(double (&PositionStart)[6],double (&PositionEnd)[6]);
    void onbtnClickedSeamPosReset();
    void onbtnClickedSeamPosSend();
    void onbtnClickedCalibrationSave(double Hand2EyePosition[6]);
    void toRobotKRLReceiveLoopRun();
    void toRobotKRLSendLoopRun();
    void frLaserSensorReceive();
    void toLaserSensorSend();
    void SeamTechTCPThreadLoopRun();
    void SeamTechLoopRun();
    void SeamTechUDPThreadLoopRun();
    void ReadLaserSensorDataY(double& value);
    void ReadLaserSensorDataZ(double& value);
    void LaserSensorDataSave();
public:
    bool getButtonStatus(ENUM_ButtonName Name);
    void readAutoCalibrationResualt(double (&value)[6]);
    void readAutoSeamStartPointResualt(double (&value)[6]);
    void readAutoSeamEndPointResualt(double (&value)[6]);
private:
    void onSeamTrackingProcess();
    void onSeamFindingProcess();
    void onSeamFindingStart2EndProcess();
    void onSeamFindingStart2EndProcess_Auto();
    void onSeamFindingStart2EndProcess_Mannual();
    void SeamFindingStart2EndProcessMannualCal();
    bool ReadLaserSensorDataValue();

    void onSeamCalibrationProcess_Auto();
    void EyeHandsAotuCalibrationandSave();
};

#endif // BACKINSTANCE_H
